var app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    saveFlog: true,
    siteName: ''
  },
  bindSiteName(e) {
    this.setData({ siteName: e.detail.value })
    if (this.data.siteName.length > 0) {
      this.setData({ saveFlog: false })
    } else {
      this.setData({ saveFlog: true })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({ siteName: options.siteName })
    console.log(options)
  },
  bindFormSubmit: function() {
    wx.showLoading({ title: '提交中' })

    var siteName = this.data.siteName
    wx.request({
      method: 'POST',
      url: app.preUrl + 'updateUser',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        siteName: siteName,
        id: app.globalData.userId
      },
      success: function(res) {
        wx.hideLoading()
        if (res.data.code === 100) {
          wx.navigateBack({
            delta: 1
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 1000
          })
        }
      }
    })
  }
})
